from config import aiConfig
from instructions.instruction import Instruction
import logging

from instructions.enum_types import ActionType, InstructionType
from prompt_template import prompt_tpl
from wechat.reply import Reply, ReplyType

logger = logging.getLogger(__name__)


class OtherInstruction(Instruction):
    def __init__(self, chatDBHandler=None, query=None):
        super().__init__(chatDBHandler=chatDBHandler, query=query)
        self.insType = InstructionType.BAVARDER
        self.prompt = aiConfig.CHARACTER_DESC + prompt_tpl.BAVARDER_PROMPT

    async def handle_query(self):
        self.chatDBHandler.add_actions(ActionType.HANDLER_QUERY)
        response = await self.query_ollama()
        if response and isinstance(response, str):
            self.chatDBHandler.ai_answer = response
        elif response is None:
            response = self.query_other()

        return Reply(ReplyType.TEXT, response)
